package marketeer;

import java.rmi.RMISecurityManager;
import java.rmi.Remote;

import net.jini.config.Configuration;
import net.jini.config.ConfigurationProvider;
import net.jini.core.lookup.ServiceID;
import net.jini.discovery.LookupDiscoveryManager;
import net.jini.export.Exporter;
import net.jini.jeri.BasicILFactory;
import net.jini.jeri.BasicJeriExporter;
import net.jini.jeri.tcp.TcpServerEndpoint;
import net.jini.lease.LeaseRenewalManager;
import net.jini.lookup.JoinManager;
import net.jini.lookup.ServiceIDListener;


public class Marketeer implements ServiceIDListener{
	
	private MarketeerClientService fMarketeerClientService;
	
	public Marketeer() {
		
		try {
		
			// Construct exporter for MarketeerClientProxy class
			Exporter exporter = new BasicJeriExporter(TcpServerEndpoint.getInstance(0), new BasicILFactory());
			fMarketeerClientService = new MarketeerClientService();
			Remote proxy = exporter.export(fMarketeerClientService);
		
			// Register service
			LookupDiscoveryManager discoveryMgr = new LookupDiscoveryManager(new String [] {"JORSEBREGGIE"}, null, null);
			JoinManager joinMgr = new JoinManager(proxy, null, this, discoveryMgr, new LeaseRenewalManager());


		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println("Marketeer started...");
	}

	public void serviceIDNotify(ServiceID serviceID) {
		System.out.println("Service registered with service ID " + serviceID.toString());
	}
}
